package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

public class UserAccountInfoListRequest extends Request {
	
	private static final long serialVersionUID = -5010021793683141464L;

	/**
	 * 注册时间范围（开始时间）
	 */
	private String startTime;
	
	/**
	 * 注册时间范围（结束时间）
	 */
	private String endTime;
	
	/**
	 * 用户绑定手机
	 */
	private String phone;
	
	/**
	 * 用户绑定邮箱
	 */
	private String email;
	
	/**
	 * 姓名
	 */
	private String realName;
	
	/**
	 * 用户id列表
	 */
	private String ids;
	
	/**
	 * 用户名
	 */
	private String accountName;
	
	/**
	 * 操作ip
	 */
	private String ip;
	
	/**
	 * 渠道代码
	 */
	private String expandCode;
	
	/**
	 * 年龄下限
	 */
	private int ageLower;
	
	/**
	 * 年龄上限
	 */
	private int ageUpper;
	
	private int pageNum;
	
	private int pageSize;
	
	@Override
	public void parse(HttpServletRequest request) {
		
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		this.startTime = requestInfo.getParameter(ApiUrlParamEnum.startTime.getParamName());
		this.endTime = requestInfo.getParameter(ApiUrlParamEnum.endTime.getParamName());
		this.pageNum = requestInfo.getIntParameter(ApiUrlParamEnum.pageNo.getParamName(), 1);
		this.pageSize = requestInfo.getIntParameter(ApiUrlParamEnum.pageSize.getParamName(), 20);
		this.phone = requestInfo.getParameter(ApiUrlParamEnum.phone.getParamName());
		this.email = requestInfo.getParameter(ApiUrlParamEnum.email.getParamName());
		this.ids = requestInfo.getParameter(ApiUrlParamEnum.ids.getParamName());
		this.ip = requestInfo.getParameter(ApiUrlParamEnum.ip.getParamName(), requestInfo.getUserIp());
		this.expandCode = requestInfo.getParameter(ApiUrlParamEnum.expandCode.getParamName(), "");
		this.ageLower = requestInfo.getIntParameter(ApiUrlParamEnum.ageLowerLimit.getParamName(), -1);
		this.ageUpper = requestInfo.getIntParameter(ApiUrlParamEnum.ageUpperLimit.getParamName(), -1);
		this.realName = requestInfo.getParameter(ApiUrlParamEnum.realName.getParamName());
		this.accountName = requestInfo.getParameter(ApiUrlParamEnum.accountName.getParamName());
		
		
		/*if (StringUtil.isEmpty(ids) && StringUtil.isEmpty(startTime) && 
				StringUtil.isEmpty(endTime) && StringUtil.isEmpty(phone) &&
				StringUtil.isEmpty(email) && StringUtil.isEmpty(expandCode) &&
				ageLower < 0 && ageUpper < 0 && StringUtil.isEmpty(realName) && 
				StringUtil.isEmpty(accountName)) {
			throw new RequestIllegalException("参数不能为空!");
		}*/
		
		if(!StringUtil.isEmpty(email) && !StringUtil.isEmail(email)) {
			throw new RequestIllegalException("非法的邮箱地址");
		}
		
		if(!StringUtil.isEmpty(phone) && !StringUtil.isMobilePhone(phone)) {
			throw new RequestIllegalException("非法的手机号码");
		}
		
		if(!StringUtil.isEmpty(ids) && !StringUtil.isNumber(ids.replaceAll(",", ""))) {
			throw new RequestIllegalException("非法的用户ID");
		}
	}
	

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}
	
	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}


	public String getExpandCode() {
		return expandCode;
	}


	public void setExpandCode(String expandCode) {
		this.expandCode = expandCode;
	}


	public int getAgeLower() {
		return ageLower;
	}


	public void setAgeLower(int ageLower) {
		this.ageLower = ageLower;
	}


	public int getAgeUpper() {
		return ageUpper;
	}


	public void setAgeUpper(int ageUpper) {
		this.ageUpper = ageUpper;
	}


	public String getAccountName() {
		return accountName;
	}


	public void setAccountName(String accountName) {
		this.accountName = accountName;
	}
	
	
	
}
